package cn.itsource.itsource.service.impl;

import cn.itsource.itsource.domain.Department;
import cn.itsource.itsource.domain.LinYu;
import cn.itsource.itsource.mapper.LinYuMapper;
import cn.itsource.itsource.query.LinYuQuery;
import cn.itsource.itsource.service.ILinYuService;
import cn.itsource.itsource.util.AjaxResult;
import cn.itsource.itsource.util.PageList;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LinYuServiceImpl implements ILinYuService {

    @Autowired
    private LinYuMapper linYuMapper;
    @Override
    public AjaxResult pageList(LinYuQuery query) {

        PageHelper.startPage(query.getCurrPage(),query.getPageSize());
        PageInfo<LinYu> pageInfo = new PageInfo<>(linYuMapper.findByQuery(query));

        PageList<LinYu> pageList=new PageList(pageInfo.getTotal(),pageInfo.getList());
        AjaxResult result = AjaxResult.success("操作成功");
        result.setData(pageList);

        return  result;
    }

    @Override
    public AjaxResult saveOrUpdate(LinYu linYu) {
        linYuMapper.save(linYu);

        return AjaxResult.success("操作成功");
    }



    @Override
    public AjaxResult del(Long id) {

        linYuMapper.del(id);

        return AjaxResult.success("删除成功");
    }
}
